package com.mjlf.hometeach.common.utils;

import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public final class WebControllerResultUtil {
    /**
     *
     * 打印接口调用接口
     * @param result
     * @param resultClass
     */
    public static void writeResult(JSONObject result, Class resultClass, HttpServletResponse response){
        Logger logger = LoggerFactory.getLogger(resultClass);

        try {
            response.getWriter().write(result.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }

        logger.info("|*result : " + result.toString());
        logger.info("|******************************************************\n\n\n");
    }

    public static void writeResult(String result, Class resultClass, HttpServletResponse response){
        Logger logger = LoggerFactory.getLogger(resultClass);

        try {
            response.getWriter().write(result);
        } catch (IOException e) {
            e.printStackTrace();
        }

        logger.info("|*result : " + result + "");
        logger.info("|******************************************************\n\n\n");
    }
}
